/**
 * Use Map to navigation:Yes
 * Check points: 1.Click a box to jump to another page 
 * 
 */
package com.tcc.assessment.studentrole.usemaptonavigation;

import org.apache.xpath.operations.String;
import org.testng.Assert;
import org.testng.annotations.Test;

import com.tcc.assessment.logic.Playback;
import com.tcc.assessment.studentrole.allowchangeanswer.Assessment2;
import com.tcc.qa.test.util.BaseTest;
import com.tcc.qa.test.util.SelLogger;
import com.tcc.qa.test.util.TableCellFinder;

/**
 * @company CampusCruiser
 * @author Emily_Wang
 * @date 2012-8-13
 */
public class Assessment28 extends BaseTest{
  int errorCount = 0;

  //Initialization Log
  private static final SelLogger logger = SelLogger.getLogger(Assessment2.class);

  @Test(description = "Goto My Assessment Page and Start Session")
  public void A_setUp() throws InterruptedException {
    Playback.initPlaybacker(getWebDriver(), "Assessment28");
  }
  @Test(description = "Page1")
  public void B_page1() throws InterruptedException {
    getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    Playback.switchWindow(getWebDriver());
    Playback.getShortAnswerObj(getWebDriver(), 2).sendKeys("2");
    Playback.getChooseOneAsnwerObj(getWebDriver(), 3, 4).click();
    Assert.assertTrue(Playback.getPageNavInfo(getWebDriver()).contains("Page 1 of 4"), "Page1 >> Pagination info is incorrect!");
    Assert.assertTrue(Playback.getTitleInfo(getWebDriver()).contains("Assessment28"), "Page1 >> Page Title is incorrect!");
    logger.pass("Navigate to page1 pass.");
  }
  @Test(description = "lead to Page3")
  public void C_page3() throws InterruptedException {
    getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    TableCellFinder.getCellLocation(getWebDriver(), "assessmentContentNav", 1, 3).click();
    Playback.switchWindow(getWebDriver());
    Playback.getShortAnswerObj(getWebDriver(), 1).sendKeys("6");
    for (int i = 0; i < 5; i++) {
      Playback.getMatchingOneObj(getWebDriver(), 2, i + 1).sendKeys(String.valueOf(i + 1));
    }
    Assert.assertTrue(Playback.getPageNavInfo(getWebDriver()).contains("Page 3 of 4"), "Page2 >> Pagination info is incorrect!");
    Assert.assertTrue(Playback.getTitleInfo(getWebDriver()).contains("Assessment28"), "Page2 >> Page Title is incorrect!");
    logger.pass("Navigate to page3 pass.");
  }
  @Test(description = "Page2")
  public void D_page2() throws InterruptedException {
    getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    TableCellFinder.getCellLocation(getWebDriver(), "assessmentContentNav", 1, 2).click();
    Playback.switchWindow(getWebDriver());
    Playback.getEssayObj(getWebDriver(), 1).sendKeys("13579");
    Playback.getFillInBlankObj(getWebDriver(), 2).sendKeys("12");
    Assert.assertTrue(Playback.getPageNavInfo(getWebDriver()).contains("Page 2 of 4"), "Page2 >> Pagination info is incorrect!");
    Assert.assertTrue(Playback.getTitleInfo(getWebDriver()).contains("Assessment28"), "Page2 >> Page Title is incorrect!");
    logger.pass("Navigate to page2 pass.");
  }
  @Test(description="Page4")
  public void E_page4(){
    getWebDriver().manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    TableCellFinder.getCellLocation(getWebDriver(), "assessmentContentNav", 1, 4).click();
    Playback.switchWindow(getWebDriver());
    Assert.assertTrue(Playback.getPageNavInfo(getWebDriver()).contains("Page 4 of 4"), "Page4 >> Pagination info is incorrect!");
    Assert.assertTrue(Playback.getTitleInfo(getWebDriver()).contains("Assessment28"), "Page4 >> Page Title is incorrect!");
    logger.pass("Navigate to page4 pass.");
  }
  @Test(description = "Finish")
  public void F_finish() throws InterruptedException {   
    Playback.finishAndClosePlaybacker(getWebDriver());
  }

}
